﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using nRoute.Components;
using nRoute.Navigation.Mapping;
using nRoute.SiteMaps;
using nRoute.ViewModels;
using TabsNavigation.Views;

namespace TabsNavigation.ViewModels
{
    [DefineNavigationContent("Content/Pages/Home/", typeof(Home))]
    [MapViewModel(typeof(Home))]
    public class HomeViewModel : NavigationViewModelBase
    {
        private const string LASTVIEWED_KEY = "__LastViewedKey";
        private const string PAGE_TITLE = "Home";

        public HomeViewModel()
        {
            base.Title = PAGE_TITLE;
        }

        public DateTime? LastViewed { get; private set; }

        #region State Management

        protected override void OnRestoreState(ParametersCollection state)
        {
            if (state != null && state.ContainsKey(LASTVIEWED_KEY))
            {
                this.LastViewed = Convert.ToDateTime(state[LASTVIEWED_KEY]);
                NotifyPropertyChanged(() => LastViewed);
            }
        }

        protected override ParametersCollection OnSaveState()
        {
            return new ParametersCollection() 
            {
                new Parameter(LASTVIEWED_KEY, DateTime.Now)
            };
        }

        #endregion

    }
}